// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.Contracts; using System.Globalization; using System.Linq; using System.Text; using System.Xml.Serialization; using LargoCommon.Abstract; namespace LargoCommon.Music { /// Rhythmical system. /// Rhythmical system is subclass of binary GSystem. It is defined by /// its order, that represents number of "ticks" in one bar. [Serializable] [XmlRoot] public sealed class RhythmicSystem : GeneralSystem { #region Fields /// /// Used systems. /// private static readonly Dictionary UsedSystems = new Dictionary(); #endregion #region Constructors /// Initializes a new instance of the RhythmicSystem class. Serializable. public RhythmicSystem() { } /// Initializes a new instance of the RhythmicSystem class. /// Degree of system. /// Order of system. public RhythmicSystem(RhythmicDegree givenDegree, byte order) : base((byte)givenDegree, order) { } #endregion #region Static methods /// /// Approximate Musical Tempo. /// /// Musical tempo. /// Returns value. public static MusicalTempo ApproximateMusicalTempo(int tempoValue) { var items = SupportCommon.GetEnumValues(typeof(MusicalTempo)); var tempo = items != null ? (from val in items where tempoValue <= val select (MusicalTempo)val).FirstOrDefault() : MusicalTempo.Tempo120; return tempo; } /// /// Get RhythmicSystem. /// /// Degree of the system. /// Order of the system. /// Returns value. public static RhythmicSystem GetRhythmicSystem(RhythmicDegree degree, byte order) { Contract.Ensures(Contract.Result() != null); var key = string.Format(CultureInfo.InvariantCulture, "{0}#{1}", degree, order.ToString(CultureInfo.CurrentCulture)); var rs = UsedSystems.ContainsKey(key) ? UsedSystems[key] : null; if (rs != null) { return rs; } rs = new RhythmicSystem(degree, order); UsedSystems[key] = rs; return rs; } #endregion #region Substructures /// /// Modality Classes. /// /// General Qualifier. /// Upper limit. /// Returns value. public Collection ModalityClasses(GeneralQualifier genQualifier, int limit) { var hv = StructuralVarietyFactory.NewRhythmicModalityVariety( StructuralVarietyType.RhythmicModalityClasses, this, genQualifier, limit); return hv.StructList; } /// /// Modality Classes. /// /// Returns value. public Collection ModalityClasses() { var hv = StructuralVarietyFactory.NewRhythmicModalityVariety( StructuralVarietyType.RhythmicModalityClasses, this, null, 10000); return hv.StructList; } /// /// Modality Instances. /// /// General Qualifier. /// Upper limit. /// Returns value. public Collection ModalityInstances(GeneralQualifier genQualifier, int limit) { var hv = StructuralVarietyFactory.NewRhythmicModalityVariety( StructuralVarietyType.Instances, this, genQualifier, limit); return hv.StructList; } /// /// Modality Instances. /// /// Returns value. public Collection ModalityInstances() { var hv = StructuralVarietyFactory.NewRhythmicModalityVariety( StructuralVarietyType.Instances, this, null, 10000); return hv.StructList; } /// /// Shape Classes. /// /// General Qualifier. /// Upper limit. /// Returns value. public Collection ShapeClasses(GeneralQualifier genQualifier, int limit) { var hv = StructuralVarietyFactory.NewRhythmicShapeVariety( StructuralVarietyType.BinaryClasses, this, genQualifier, limit); return new Collection(hv.StructList); } /// /// Shape Classes. /// /// Returns value. public Collection ShapeClasses() { var hv = StructuralVarietyFactory.NewRhythmicShapeVariety( StructuralVarietyType.BinaryClasses, this, null, 10000); return hv.StructList; } /// /// Shape Instances. /// /// General Qualifier. /// Upper limit. /// Returns value. public Collection ShapeInstances(GeneralQualifier genQualifier, int limit) { var hv = StructuralVarietyFactory.NewRhythmicShapeVariety( StructuralVarietyType.Instances, this, genQualifier, limit); return hv.StructList; } /// /// Shape Instances. /// /// Returns value. public Collection ShapeInstances() { var hv = StructuralVarietyFactory.NewRhythmicShapeVariety( StructuralVarietyType.Instances, this, null, 10000); return hv.StructList; } /// /// Struct Classes. /// /// General Qualifier. /// Upper limit. /// Returns value. public Collection StructClasses(GeneralQualifier genQualifier, int limit) { var rv = StructuralVarietyFactory.NewRhythmicStructuralVariety( StructuralVarietyType.Classes, this, genQualifier, limit); return rv.StructList; } /// /// Struct Classes. /// /// Returns value. public Collection StructClasses() { var hv = StructuralVarietyFactory.NewRhythmicStructuralVariety( StructuralVarietyType.Classes, this, null, 10000); return hv.StructList; } /// /// Struct Instances. /// /// General Qualifier. /// Upper limit. /// Returns value. public Collection StructInstances(GeneralQualifier genQualifier, int limit) { var hv = StructuralVarietyFactory.NewRhythmicStructuralVariety( StructuralVarietyType.Instances, this, genQualifier, limit); return hv.StructList; } /// /// Struct Instances. /// /// Returns value. public Collection StructInstances() { var hv = StructuralVarietyFactory.NewRhythmicStructuralVariety( StructuralVarietyType.Instances, this, null, 10000); return hv.StructList; } #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.AppendLine("Rhythmical system"); s.AppendLine(base.ToString()); return s.ToString(); } #endregion } }